﻿@{
    Layout = null;
}
@model Freshbox2._0.MODEL.admin
<!DOCTYPE html>

<html>
<head>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="icon" type="image/gif" href="~/img/animated_favicon1.gif">
    <meta name="viewport" content="width=device-width" />
    <link href="~/UILibs/easyui/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/UILibs/easyui/themes/icon.css" rel="stylesheet" />
    <link href="~/Css/css.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script src="~/UILibs/easyui/jquery.easyui.min.js"></script>
    <script src="~/UILibs/easyui/locale/easyui-lang-zh_CN.js"></script>

    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.edatagrid.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>

    <title></title>
    <script type="text/javascript">
        $(function () {
            $("#data").datagrid({
                fit: true,
                title: '商品补够信息列表',  //
                striped: true,
                rownumbers: true,
                singleSelect: true,
                onClickRow: onClickRow,
                columns:
                    [[{
                        field: 'ck',
                        checkbox: true
                    }, {
                        field: 'replenishID',
                        title: '补购编号',
                        width: 200,
                        height: 50,
                        halign: 'center',
                        align: 'center',

                    }, {
                        // waresCode   waresName    waresSpec  waresUnit waresquantity waresPrice replenishID
                        field: 'waresCode',
                        title: '商品编号',
                        width: 150,
                        height: 50,
                        halign: 'center',
                        sortable: true,
                        align: 'center'
                    }, {
                        field: 'waresName',
                        title: '商品名称',
                        width: 200,
                        height: 50,
                        halign: 'center',
                        align: 'center',

                    }, {
                        field: 'waresPrice',
                        title: '商品价格',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'waresSpec',
                        title: '规格',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'waresUnit',
                        title: '单位',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'waresquantity',
                        title: '剩余数量',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    },
                    {
                        field: 'replenishNum', title: '请输入补够数量', width: 100, halign: 'center',
                        editor: { type: 'text', options: {} }
                    }
                    ]],

                url: pageConfig.getAction,
                pagination: true,
                pageSize: 25,
                pageList: [25, 30, 35, 40],
                sortName: 'waresCode',
                toolbar: '#tool',
                sortOrder: 'desc',
                autoSave: true,
                onSave: function (index, row) {
                    $("#data").datagrid('refreshRow');
                }
            });

        });
    </script>
    <script type="text/javascript">
        //批量提交  执行方法
        function save() {

            var len = $("#data").datagrid('getChanges').length;//获取有变化的行的长度
            //alert(len);
            //alert("执行save方法");
            if (len > 0) {

                var inserted = $("#data").datagrid('getChanges', "inserted");//获取新添加的行
                var deleted = $("#data").datagrid('getChanges', "deleted");//获取删除的行
                var updated = $("#data").datagrid('getChanges', "updated");//获取修改的行
                var data = {};
                data.Inserted = inserted;
                data.Deleted = deleted;
                data.Updated = updated;
                //alert(data.Updated);
                $.ajax({

                    url: '/Replenish/SaveReplenishNum',
                    type: 'POST',
                    data: JSON.stringify(data),
                    contentType: "application/json; charset=utf-8",

                    dataType: "json",
                    beforeSend: function () {
                        $.messager.progress({ title: "执行中", text: "" });
                    },
                    success: function (data) {
                        $.messager.alert("成功", data.msg, "info");
                    },
                    error: function (data) {
                        $.messager.alert("警告", "系统故障", "error", "")
                    },
                    complete: function () {

                        complete();
                    }
                });

            }
            else {
                alert("没有发生变化的数据！");
                return;
            }

        }

        var editIndex = undefined;
        function endEditing() {
            //alert("endEditing"+editIndex); 
            if (editIndex == undefined) { return true }
            if ($('#data').datagrid('validateRow', editIndex)) {

                $('#data').datagrid('endEdit', editIndex);
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        }
        function onClickRow(index) {
            // alert(index); 能执行  
            if (editIndex != index) {
                if (endEditing()) {
                    $('#data').datagrid('selectRow', index)
                            .datagrid('beginEdit', index);
                    editIndex = index;
                } else {
                    $('#data').datagrid('selectRow', editIndex);
                }
            }
        }

        function getChanges() {
            var rows = $('#data').datagrid('getChanges');
            alert(rows.length + ' rows are changed!');
        }

        var pageConfig = {
            type: null,
            getAction: '@Url.Action("GetLess")',
            saveAction: '@Url.Action("Save")',
            delAction: '@Url.Action("ModifyState")',
            modifyAction: '@Url.Action("Modify")',
            getOneAction: '@Url.Action("GetOnlyOne")',
        };


        function searchData() {
            $("#data").datagrid('load', {
                adminUsername: $("#txtName").val()

            });
        }
        function complete() {
            $("#data").datagrid("load");
            $.messager.progress("close");

        } 
        function excel()
        {
            window.location.href = "/Replenish/Export";
        }
    </script>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%">
    <div data-options="region:'center'">
        <table id="data"></table>
        <div id="tool" style="padding: 10px;">
            <div style="margin-bottom: 10px;">
                <div style="margin-bottom: 10px;" align="center">
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                   @* <a class="easyui-linkbutton"  iconcls="icon-print" onclick="excel();">导出补够Exel</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp *@
                    <a class="easyui-linkbutton" style="width:120px;height:60px" iconcls="icon-add" onclick="save()">提交补够信息</a>

                </div>

            </div>
        </div>
    </div>




</body>
</html>
